<?php

namespace think\wework\Api;

use think\wework\Abstracts\WeworkApiWithToken;

class CheckIn extends WeworkApiWithToken
{
    const TYPE_COMMUTE = 1;
    const TYPE_OUTSIDE = 2;
    const TYPE_ALL = 3;

    private static ?CheckIn $instance = null;
    public static function getInstance(): CheckIn
    {
        if(!self::$instance instanceof CheckIn) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * 获取打卡规则
     *
     * @param int $datetime
     * @param array $userIdList
     * @return array
     */
    public function getOption(int $datetime, array $userIdList): array
    {
        $json = ['datetime' => $datetime, 'useridlist' => $userIdList];
        return $this->httpClient->post('checkin/getcheckinoption', compact('json'))->toArray();
    }

    /**
     * 获取打卡数据
     *
     * @param int $type
     * @param int $startTime
     * @param int $endTime
     * @param array $userIdList
     * @return array
     */
    public function getData(int $type, int $startTime, int $endTime, array $userIdList): array
    {
        $json = [
            'opencheckindatatype' => $type,
            'starttime' => $startTime,
            'endtime' => $endTime,
            'useridlist' => $userIdList
        ];
        return $this->httpClient->post('checkin/getcheckindata', compact('json'))->toArray();
    }
}
